package io.kimmking.chatoom.server.config;

import io.kimmking.chatoom.server.boot.NettyServerBootStrap;
import io.kimmking.chatoom.server.handler.NettyServerMsgHandler;
import io.kimmking.common.zookeeper.zktemplate.ZookeeperTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
public class NettyServerAutoConfigure {

    @Bean(initMethod = "start", destroyMethod = "close")
    @ConditionalOnBean({NettyServerConfig.class, NettyServerMsgHandler.class, ZookeeperTemplate.class})
    @ConditionalOnMissingBean
    public NettyServerBootStrap nettyServerBootStrap(NettyServerConfig nettyServerConfig,
                                                     NettyServerMsgHandler nettyServerMsgHandler,
                                                     ZookeeperTemplate zookeeperTemplate){
        return new NettyServerBootStrap(nettyServerConfig, nettyServerMsgHandler, zookeeperTemplate);
    }
}
